<template>
  <div>
    <div>
      <input type="text" v-model="key" placeholder="设置key">
      <input type="text" v-model="value" placeholder="设置value">
      <button @click="setCookie()">设置cookie</button>
    </div>
    <div>
      <input type="text" v-model="clearKey" placeholder="清除key">
      <button @click="clearCookie()">清除cookie</button>
    </div>
    <div>
      <button @click="secondTest()">第二测试</button>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      token: 'token',
      key: '',
      value: '',
      clearKey: ''
    }
  },
  methods: {
    setCookie () {
      let date = new Date()
      date.setDate(date.getDate() + 1)
      console.log(date)
      document.cookie = this.key + '=' + this.value + ';expires=' + date
    },
    clearCookie () {
      let date = new Date()
      date.setTime(date.getTime() - 10000)
      console.log(date)
      document.cookie = this.clearKey + '=;expires=' + date.toGMTString()
    },
    test () {
      console.log('abcdef'.includes('c')) // true
      console.log('abcdef'.startsWith('a')) // true
      console.log('abcdef'.endsWith('f')) // true
      console.log('a'.repeat(5)) // aaaaa
      for (let c of 'abc') {
        console.log('c:' + c)
      }
      let obj1 = [1, 2]
      console.log(Array.isArray(obj1)) // true
      let obj2 = {'1': 2}
      console.log(Array.isArray(obj2)) // false
      let a = [1, 3, -4, 10].find(function (value, index, arr) {
        console.log('arr:' + arr)
        return value < 0
      }) // -4
      console.log(a)
      let b = [1, 3, -4, 10].findIndex(function (value, index, arr) {
        return value < 0
      }) // 2
      console.log(b)
      console.log('-----------------keys()')
      // keys values() entries()
      let testArray = ['a', 'b']
      for (let index of testArray.keys()) {
        console.log(index) // 0 1
      }
      // for (let index of testArray.values) {
      //   console.log(index) // 0 1
      // }
      for (let [index, elem] of testArray.entries()) {
        console.log(index, elem) // 0 'a' 1 'b'
      }
      console.log('--------------简写')
      let testA = 'abc'
      let testB = {testA}
      console.log(testB)
      let objA = {a: 1, b: 2}
      let objB = {c: 1}
      let objC = {a: 4}
      let objD = Object.assign(objA, objB, objC)
      console.log('objA:' + JSON.stringify(objA)) // {a: 4, b: 2, c: 1}
      console.log('objB:' + JSON.stringify(objB)) // {c: 1}
      console.log('objC:' + JSON.stringify(objC)) // {a: 4}
      console.log('objD:' + JSON.stringify(objD)) // {a: 4, b: 2, c: 1}
    },
    secondTest () {
      let objA = {a: 1, b: 2}
      console.log(Object.keys(objA)) // ['a', 'b']
      console.log(Object.values(objA)) // [1, 2]
      console.log(Object.entries(objA)) // [['a', 1], ['b', 2]]
      let [a, b, c, d] = [1, 2, 3]
      console.log(a, b, c, d)
      let {f: aaa, g, h} = {
        f: 1,
        g: 2,
        h: 3
      }
      // console.log(f) // 1
      console.log('a:' + aaa)
      console.log(g) // 2
      console.log(h) // 3
      let objB = {a: 3, b: 4}
      function test ({a = 2, b}) {
        console.log('a:' + a) // 2
        console.log('b:' + b) // 4
      }
      test(objB)
      let objC = {aa: 1, bb: 2}
      let { aa, bb } = objC
      console.log(aa, bb)
    }
  },
  mounted () {
    this.test()
  }
}
</script>

<style lang="styl">
  body
    height 1200px
</style>
